home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Ham⁄GPS / SoftKiss.src.1.8 Folder / SoftKiss.src.1.8.sit / SoftKiss.src.1.8 / lib / sfk_drvr_find.c < prev    next >
Text File  |  1993-03-08  |  3KB  |  90 lines

  1. /*
  2.  * find the driver number of the softkiss driver
  3.  * by Aaron Wohl (aw0g+@andrew.cmu.edu) jul 1990
  4.  * Carnegie-Mellon University
  5.  * Special Projects
  6.  * Pittsburgh, PA 15213-3890
  7.  * (412)-268-5032
  8.  *
  9.  * special thanks to Luni and Rich Brown @ Dartmouth
  10.  *
  11.  * Luni wrote the MacTCP emulator for macmach from which this file
  12.  * borrows liberaly.
  13.  *
  14.  * Rich Brown provided the source to Dartmouth's BlitzNotify installer
  15.  * which was a big help.
  16.  *
  17.  * Unlike other softkiss source files which are for THINK C compilation
  18.  * only, this module compiles with MPW c also.
  19.  * So be carefull about sizeof(int) in THINK == 2
  20.  * and sizeof(int) in MPW == 4 if you make any changes.
  21.  *
  22.  */
  23.  
  24. #include "sfk_codecheck.h"
  25. #include "sfk_drvr_find.h"
  26.  
  27. #define drvrName 18        /*length byte and name of driver [string]*/
  28.  
  29. /*
  30.  * returns the refnum of the passed driverName
  31.  * or zero if it isn't installed.  If no driver
  32.  * is found free_ref_num returns
  33.  * a refnum that is free both in the
  34.  * unit table and in the system file and any open
  35.  * resource forks.  if there are no free driver slots
  36.  * free_ref_num returns zero
  37.  * if a driver is found the value returned in free_ref_num
  38.  * is indeterminant
  39.  * The ref num free_ref_num returns is currently the largest free
  40.  * Only ref nums less than -12 are considered
  41.  */
  42. short sfk_drvr_find(unsigned char *driverName,short *free_ref_num)
  43. {
  44.   short negCount;
  45.   short dRef;
  46.   DCtlHandle     dCtl;
  47.   char            *drivePtr;
  48.   short         result=0;
  49.   char             **handle;
  50.  
  51.   if(free_ref_num!=0)
  52.     *free_ref_num=0;        /*assume no free slots*/
  53.   negCount = -UnitNtryCnt; /*get -(table size)*/
  54.         
  55.   /*Check to see that driver is installed, obtain refNum.*/
  56.   /*Assumes that an Open was done previously -- probably by an INIT.*/
  57.   /*Driver doesn't have to be open now, though.*/
  58.         
  59.   SetResLoad(FALSE);
  60.   /*we'll start with driver refnum == -12, right after .ATP entry*/
  61.   /*Look through unit table until we find the driver or reach the end.*/
  62.   for(dRef = -12;(dRef != negCount);dRef--) {
  63.  
  64.     dCtl = GetDCtlEntry(dRef); /*get handle to DCE*/
  65.  
  66.     if (dCtl == 0L) {
  67.       if(free_ref_num!=0)
  68.         if((handle=GetResource('DRVR',(-dRef)-1))==0)
  69.           *free_ref_num=dRef;
  70.         else
  71.           ReleaseResource(handle);
  72.     } else if (( (**dCtl).dCtlDriver != 0L) ) {
  73.       if ((**dCtl).dCtlFlags & dRAMBased)
  74.         drivePtr = *(Handle) (**dCtl).dCtlDriver;
  75.       else
  76.         drivePtr = (**dCtl).dCtlDriver;
  77.             
  78.       if ((drivePtr != 0L) &&  
  79.         (EqualString((void *)(drivePtr + drvrName),(void *)driverName,0,0))) {
  80.          result=dRef;
  81.          break;
  82.       }
  83.       
  84.    }
  85.   }
  86.         
  87.   SetResLoad(TRUE);
  88.   return result;
  89. }
  90.